﻿
#ifndef __MyLib_config_h__
#define __MyLib_config_h__
#include "config.h"


/****************************************** RTC 定义   *****************************************************/

//#define CounterSecond ApiD.Sec
//#define M_second      ApiD.Msec

/***************************************** 串口资源的分配定义 **********************************************/

extern void OSTimeDly(INT32U Delay_t);
#define COM_BUF_END_ADDR 0x20020000 /* 串口缓存的结束地址 */ 

//	#define USER_UART_DEAL   /* 串口处理的主函数在USER层时的处理方式 */
//	#define COM0            /*  COM1 对应多一个接收缓存指针处理   */

/*---------------       GPIOX_T, T_N_, GPIO_AF_T,   	     GPIOX_R, R_N_, GPIO_AF_R   -----------------------------*/
	#define  COM1_IO_   GPIOA,    9,   GPIO_AF7_USART1 , 	 GPIOA,   10,   GPIO_AF7_USART1 ,  OSSem_COM1, (RCC_AHB1ENR_GPIOAEN|RCC_AHB1ENR_GPIOAEN)
 	#define  COM2_IO_   GPIOD,    5,   GPIO_AF7_USART2 , 	 GPIOD,    6,   GPIO_AF7_USART2 ,  OSSem_COM2, (RCC_AHB1ENR_GPIODEN|RCC_AHB1ENR_GPIODEN)
// 	#define  COM3_IO_   GPIOB,   10,   GPIO_AF7_USART3 , 	 GPIOB,   11,   GPIO_AF7_USART3 ,  OSSem_COM3, (RCC_AHB1ENR_GPIOBEN|RCC_AHB1ENR_GPIOBEN)
// 	#define  COM4_IO_   GPIOC,   10,   GPIO_AF8_UART4  , 	 GPIOC,   11,   GPIO_AF8_UART4  ,  OSSem_COM4, (RCC_AHB1ENR_GPIOCEN|RCC_AHB1ENR_GPIOCEN)
// 	#define  COM5_IO_   GPIOC,   12,   GPIO_AF8_UART5  , 	 GPIOD,    2,   GPIO_AF8_UART5  ,  OSSem_COM5, (RCC_AHB1ENR_GPIOCEN|RCC_AHB1ENR_GPIODEN)
 	#define  COM6_IO_   GPIOC,    6,   GPIO_AF8_USART6 , 	 GPIOC,    7,   GPIO_AF8_USART6 ,  OSSem_COM6, (RCC_AHB1ENR_GPIOCEN|RCC_AHB1ENR_GPIOCEN)
// 	#define  COM7_IO_   GPIOE,    8,   GPIO_AF8_UART7  , 	 GPIOE,    7,   GPIO_AF8_UART7  ,  OSSem_COM7, (RCC_AHB1ENR_GPIOEEN|RCC_AHB1ENR_GPIOEEN)
// 	#define  COM8_IO_   GPIOE,    1,   GPIO_AF8_UART8  , 	 GPIOE,    0,   GPIO_AF8_UART8  ,  OSSem_COM8, (RCC_AHB1ENR_GPIOEEN|RCC_AHB1ENR_GPIOEEN)
//	#define  COM9_IO_   GPIOD,   15,   GPIO_AF11_UART9 , 	 GPIOD,   14,   GPIO_AF11_UART9 ,  OSSem_COM9, (RCC_AHB1ENR_GPIODEN|RCC_AHB1ENR_GPIODEN)
//	#define  COMA_IO_   GPIOE,    3,   GPIO_AF11_UART10, 	 GPIOE,    2,   GPIO_AF11_UART10,  OSSem_COMA, (RCC_AHB1ENR_GPIOEEN|RCC_AHB1ENR_GPIOEEN)
/*-----------  485反向引脚 -----------*/
//	#define GPIO_COM1_485_TR  GPIOA   
//	#define GPIO_COM2_485_TR  GPIOA   
//	#define GPIO_COM3_485_TR  GPIOE   
//	#define GPIO_COM4_485_TR  GPIOA   
//	#define GPIO_COM5_485_TR  GPIOA   
//	#define GPIO_COM6_485_TR  GPIOA   
//	#define GPIO_COM7_485_TR  GPIOA   
//	#define GPIO_COM8_485_TR  GPIOA   
//	#define GPIO_COM9_485_TR  GPIOA   
//	#define GPIO_COMA_485_TR  GPIOA   

//	#define PinX_COM1_485_TR  11u
//	#define PinX_COM2_485_TR  11u
//	#define PinX_COM3_485_TR  15u
//	#define PinX_COM4_485_TR  11u
//	#define PinX_COM5_485_TR  11u
//	#define PinX_COM6_485_TR  11u
//	#define PinX_COM7_485_TR  11u
//	#define PinX_COM8_485_TR  11u
//	#define PinX_COM9_485_TR  11u
//	#define PinX_COMA_485_TR  11u
/*-----------  缓存长度定义 -----------*/
	#define COM1_RL	0x800u	
	#define COM2_RL	0x800u	
	#define COM3_RL	0x00u  
	#define COM4_RL	0x00u  
	#define COM5_RL	0x00u  
	#define COM6_RL	0x800u  
	#define COM7_RL	0x00u  
	#define COM8_RL	0x00u  
	#define COM9_RL	0x00u  
	#define COMA_RL	0x00u  
	
	#define COM1_TL	0x400u	
	#define COM2_TL	0x400u	
	#define COM3_TL	0x00u  
	#define COM4_TL	0x00u  
	#define COM5_TL	0x00u  
	#define COM6_TL	0x400u  
	#define COM7_TL	0x00u  
	#define COM8_TL	0x00u  
	#define COM9_TL	0x00u  
	#define COMA_TL	0x00u  
/*-----------  RX DMA 配置 -----------*/
	#define COM1_R_DMA_      DMA2_Stream2, DMA_CHANNEL_4
	#define COM2_R_DMA_      DMA1_Stream5, DMA_CHANNEL_4
//	#define COM3_R_DMA_      DMA1_Stream1, DMA_CHANNEL_4          /*同COM7 T_DMA 共用*/
	#define COM4_R_DMA_      DMA1_Stream2, DMA_CHANNEL_4
//	#define COM5_R_DMA_      DMA1_Stream0, DMA_CHANNEL_4          /*同COM8 T_DMA 共用*/
	#define COM6_R_DMA_      DMA2_Stream1, DMA_CHANNEL_5
//	#define COM7_R_DMA_      DMA1_Stream3, DMA_CHANNEL_5          /*同COM3 T_DMA 共用*/
//	#define COM8_R_DMA_      DMA1_Stream6, DMA_CHANNEL_5          /*同COM2 T_DMA 共用*/
//	#define COM9_R_DMA_      DMA2_Stream7, DMA_CHANNEL_0          /*同COM1 T_DMA 共用*/
//	#define COMA_R_DMA_      DMA2_Stream3, DMA_CHANNEL_9  
/*-----------  TX DMA 配置 -----------*/
	#define COM1_T_DMA_      DMA2_Stream7, DMA_CHANNEL_4, DMA2->HIFCR, DMA_Stream7_IT_MASK		/*同COM9 R_DMA 共用*/
	#define COM2_T_DMA_      DMA1_Stream6, DMA_CHANNEL_4, DMA1->HIFCR, DMA_Stream6_IT_MASK      /*同COM8 R_DMA 共用*/
	#define COM3_T_DMA_      DMA1_Stream3, DMA_CHANNEL_4, DMA1->LIFCR, DMA_Stream3_IT_MASK      /*同COM7 R_DMA 共用*/
	#define COM4_T_DMA_      DMA1_Stream4, DMA_CHANNEL_4, DMA1->HIFCR, DMA_Stream4_IT_MASK
	#define COM5_T_DMA_      DMA1_Stream7, DMA_CHANNEL_4, DMA1->HIFCR, DMA_Stream7_IT_MASK
	#define COM6_T_DMA_      DMA2_Stream6, DMA_CHANNEL_5, DMA2->HIFCR, DMA_Stream6_IT_MASK
	#define COM7_T_DMA_      DMA1_Stream1, DMA_CHANNEL_5, DMA1->LIFCR, DMA_Stream1_IT_MASK      /*同COM3 R_DMA 共用*/
	#define COM8_T_DMA_      DMA1_Stream0, DMA_CHANNEL_5, DMA1->LIFCR, DMA_Stream0_IT_MASK 	    /*同COM5 R_DMA 共用*/
//	#define COM9_T_DMA_      DMA2_Stream0, DMA_CHANNEL_1, DMA2->LIFCR, DMA_Stream0_IT_MASK
//	#define COMA_T_DMA_      DMA2_Stream5, DMA_CHANNEL_9, DMA2->HIFCR, DMA_Stream5_IT_MASK 

 /******************************************  硬件喂狗定义 *****************************************************/

//#define _TaskWD_USE_    /*  定义是否启用任务看门狗功能 */
#define WD_FEED             IWDG->KR = 0xAAAA
#define WD_FEED_SOFT        {extern u8 WD_FEED_flag; WD_FEED_flag = 50;}


/******************************************  多任务相关定义 *****************************************************/
/* 信号量分配 */
#define OSSem_COM1   1
#define OSSem_COM2   1
#define OSSem_COM6   1


#define OSSem_Pend(Sem_f_, xTicksToWait_)		// OSSemPend_(Sem_f_, xTicksToWait_)
#define OSSem_Post(Sem_f_)						// OSSemPost_(Sem_f_)
#define OSSem_Create(Sem_f_)					// OSSemCreate_(Sem_f_)

/******************************************  片内flash 分配定义 *****************************************************/

/*BOOT程序位置定义*/
#define BOOT_PR_BEG_ADDR		    ADDR_FLASH_SECTOR_0			//BOOT程序位置

/*硬件参数位置定义*/
#define HardWare_PARA_ADDR		    ADDR_FLASH_SECTOR_1			//参数区的位置
#define HardWare_PARA_SECTOR	    FLASH_SECTOR_1

/*设置参数地址 */
#define PARA_SECTOR0			    FLASH_SECTOR_2
#define PARA_SECTOR1			    FLASH_SECTOR_3
#define PARA_SECTOR0_ADDR           ADDR_FLASH_SECTOR_2
#define PARA_SECTOR1_ADDR           ADDR_FLASH_SECTOR_3
#define PARA_END_ADDR			    ADDR_FLASH_SECTOR_4

#define PR_LEN_MAX                  0x20000

/*程序运行地址*/
#define PR_REAL_RUN_ADDR            0x20000000

/*初始程序地址*/
#define PR_TEST_ADDR                ADDR_FLASH_SECTOR_10
/*程序保存地址*/
#define PR_SAVE_ADDR1               ADDR_FLASH_SECTOR_5
#define PR_SAVE_ADDR2               ADDR_FLASH_SECTOR_11
#define PR_SAVE_Sect1               FLASH_SECTOR_5
#define PR_SAVE_Sect2               FLASH_SECTOR_11

/******************************************  中断向量 分配定义 *****************************************************/

#define SCB_VTOR_ADDR_ReLocation		0						/* 是否重新拷贝中断向量地址 */
#define SCB_VTOR_EraseSector    		!!!!
#define SCB_VTOR_ADDR           		(PR_REAL_RUN_ADDR + 0x100)		/* 中断向量地址 */
										//BIOS_PR_BEG_ADDR + 0x100;	//FLASH_BASE | MAIN_PROGRAME_ADDR; /* Vector Table Relocation in Internal FLASH */
										//PR_REAL_RUN_ADDR + 0x100;	//在ram中运行的程序
/******************************************  upload 定义 *****************************************************/

#define upload_task_TaskWD_Feed()         // TaskWD_Feed(TASK_PRI_MAIN)         
#define upload_task_TaskWD_set(dly_)      // TaskWD_Create(TASK_PRI_MAIN, dly_);

/* Spiflash_PrFile_check_SemOFlash 程序标识和运行地址定义 */
//	#define PR_1_FLG  PR_FLG_DtuV31_BIOS
//	#define PR_2_FLG  PR_FLG_DtuV31_USER
//	#define PR_3_FLG 
//	#define PR_4_FLG 
//	#define PR_1_RUN  BIOS_PR_BEG_ADDR
//	#define PR_2_RUN  USER_PR_BEG_ADDR
//	#define PR_3_RUN 
//	#define PR_4_RUN 

#define Dbg_f_20ms_SET_UpLoad(dly_)   Dbg_f_20ms = dly_           //调试信息屏蔽延时设置




#endif



